//
//  MineAwardViewController.m
//  renmingongshe
//
//  Created by macbook on 2017/11/7.
//  Copyright © 2017年 xiaodian. All rights reserved.
//

#import "MineAwardViewController.h"
#import "PickupMoneyViewController.h"
#import "MineAddAcountController.h"
#import "MineTransformViewController.h"
#import "PickUpMoRecordViewController.h"
#import "MineAddBankCountViewController.h"

@interface MineAwardViewController ()

@property (strong, nonatomic) UIView *bgView;
@property (strong, nonatomic) UIView *RightTopView;
@property (weak, nonatomic) IBOutlet UILabel *MoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *AwardRemake;

@end

@implementation MineAwardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.titleLabel.text = @"我的奖励";
    [self.rightBtn setTitle:@"添加账户" forState:UIControlStateNormal];
    self.view.backgroundColor = [UIColor colorWithHex:0xf2f2f2];
    
    _AwardRemake.layer.borderColor = [[UIColor whiteColor]CGColor];
    _AwardRemake.layer.borderWidth = 1.0f;
    [_AwardRemake.layer setCornerRadius:10.0];
    _AwardRemake.layer.masksToBounds = YES;
    
    [self createBgView];
}

-(void)viewWillAppear:(BOOL)animated
{
    [self downloadData];
}

- (void)createBgView
{
    _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, WIDTH, HEIGHT-70)];
    _bgView.backgroundColor = [UIColor blackColor];
    _bgView.alpha = 0.5;
    _bgView.hidden = YES;
    [self.view addSubview:_bgView];
    
    _RightTopView = [[UIView alloc] initWithFrame:CGRectMake(WIDTH-(WIDTH*100/320), 70, (WIDTH*100/320), WIDTH*122/320)];
    _RightTopView.backgroundColor = [UIColor whiteColor];
    _RightTopView.hidden = YES;
    [self.view addSubview:_RightTopView];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(0, 0, _RightTopView.width, _RightTopView.height/3);
    [btn1 setTitle:@"支付宝" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn1.backgroundColor = [UIColor whiteColor];
    [btn1 addTarget:self action:@selector(addAcount:) forControlEvents:UIControlEventTouchUpInside];
    btn1.tag = 1;
    btn1.titleLabel.font = [UIFont systemFontOfSize:14];
    [_RightTopView addSubview:btn1];
    
    UIView *firstLine = [[UIView alloc] initWithFrame:CGRectMake(0, btn1.bottom, _RightTopView.width, 1)];
    firstLine.backgroundColor = [UIColor colorWithHex:0xf2f2f2];
    [_RightTopView addSubview:firstLine];
    
    UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(0, firstLine.bottom, _RightTopView.width, _RightTopView.height/3)];
    btn2.tag = 2;
    btn2.titleLabel.font = [UIFont systemFontOfSize:14];
    btn2.backgroundColor = [UIColor whiteColor];
    [btn2 setTitle:@"微信" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(addAcount:) forControlEvents:UIControlEventTouchUpInside];
    [_RightTopView addSubview:btn2];
    
    UIView *secondLine = [[UIView alloc] initWithFrame:CGRectMake(0, btn2.bottom, _RightTopView.width, 1)];
    secondLine.backgroundColor = [UIColor colorWithHex:0xf2f2f2];
    [_RightTopView addSubview:secondLine];
    
    UIButton *btn3 = [[UIButton alloc]initWithFrame:CGRectMake(0, secondLine.bottom, _RightTopView.width, _RightTopView.height/3)];
    btn3.tag = 3;
    btn3.titleLabel.font = [UIFont systemFontOfSize:14];
    btn3.backgroundColor = [UIColor whiteColor];
    [btn3 setTitle:@"银行卡" forState:UIControlStateNormal];
    [btn3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn3 addTarget:self action:@selector(addAcount:) forControlEvents:UIControlEventTouchUpInside];
    [_RightTopView addSubview:btn3];
}


- (void)downloadData
{
    [self.view loadingOnAnyView];
    [THWManager PostHttp:API(MineAward) Parameters:@{@"userToken":[Utils getUserToken]} Success:^(id responseObject) {
        [self.view removeAnyView];
        if ([String(responseObject[@"status_code"]) isEqualToString:@"1008"]) {
            [self.view Message:responseObject[@"msg"]];
        }else{
            _MoneyLabel.text = [NSString stringWithFormat:@"%@", responseObject[@"data"]];
        }
    } andFalse:^(NSError *error) {
        [self.view removeAnyView];
    }];
}

- (void)rightBtnClick
{
    _bgView.hidden = NO;
    _RightTopView.hidden = NO;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    _bgView.hidden = YES;
    _RightTopView.hidden = YES;
}

- (void)addAcount:(UIButton*)btn
{
    _bgView.hidden = YES;
    _RightTopView.hidden = YES;
    if (btn.tag == 3) {
        //银行卡
        MineAddBankCountViewController *bank = [[MineAddBankCountViewController alloc] init];
        [self.navigationController pushViewController:bank animated:YES];
    }else{
        //支付宝 微信
        MineAddAcountController *add = [[MineAddAcountController alloc]init];
        add.type = btn.tag;
        [self.navigationController pushViewController:add animated:YES];
    }
    
}
- (IBAction)PickUpClick:(UIButton *)sender {
    PickupMoneyViewController *pickup = [[PickupMoneyViewController alloc] init];
    [self.navigationController pushViewController:pickup animated:YES];
}

- (IBAction)PickUpRecord:(UIButton *)sender {
    PickUpMoRecordViewController *record = [[PickUpMoRecordViewController alloc] init];
    record.type = @"pick";
    [self.navigationController pushViewController:record animated:YES];
}

- (IBAction)TransferClick:(UIButton *)sender {
    MineTransformViewController *tranfrom = [[MineTransformViewController alloc] init];
    [self.navigationController pushViewController:tranfrom animated:YES];
}
- (IBAction)TransfromRecordClick:(UIButton *)sender {
    PickUpMoRecordViewController *record = [[PickUpMoRecordViewController alloc] init];
    record.type = @"trans";
    [self.navigationController pushViewController:record animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
